package com.example.springboot01.controller;


import com.example.springboot01.model.TUser;
import com.example.springboot01.service.TUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class TUserController {

    @Autowired
    private  TUserService tUserService;

    public TUserController(TUserService tUserService) {
        this.tUserService = tUserService;
    }

    @RequestMapping(value = "/api/admin/login",method = RequestMethod.POST)
    public @ResponseBody Object login(@RequestBody TUser tUser){


        if (tUser == null){
            return "yonghu bu cun zai";
        }else{
            System.out.println("用户存在");
            System.out.println(tUser.toString());
            return tUserService.queryTUserByUserNameAndPassword(tUser);
        }
    }

    @RequestMapping(value = "/api/admin/selectById/{id}",method = RequestMethod.POST)
    public @ResponseBody Object selectById( @PathVariable Integer id){

        TUser tUser = tUserService.queryTUserByID(id);

        if (tUser == null){
            System.out.println("id  :  " + id);
            return "yonghu bu cun zai";
        }else{
            System.out.println("用户存在");
            System.out.println(tUser.toString());
            return tUser;
        }
    }

    @RequestMapping(value = "calu/{num}")
    public @ResponseBody Float calu(@PathVariable Integer num){
        Float sum;
        Float tempFloat = 0.0f;
        sum = 0.0f;
        for (int i = 1; i < num; i++) {
            tempFloat = 0.5f;
            for (int j = 1; j < i; j++) {
                tempFloat *=  0.5f;
            }
            sum +=  tempFloat;
        }
        return  sum;
    }
}
